#include <iostream>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <sstream>
#include <string>

bool is_simple(int x) {
    if (x < 2) return false;
    if (x == 2) return true;
    if (x % 2 == 0) return false;
    int sqrtx = (int)sqrt(x);
    for (int d = 3; d <= sqrtx; d += 2) {
        if (x % d == 0) return false;
    }
    return true;
}

std::vector<int> spr() {
    std::vector<int> sp;
    for (int i = 101; i < 998; i++) {
        if (is_simple(i)) {
            sp.push_back(i);
        }
    }
    return sp;
}

int main() {
    std::unordered_map<std::string, std::string> Alfa = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
        {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
    };
    std::string s;
    std::getline(std::cin, s);
    std::stringstream ss(s);
    std::string sw;
    std::string p = "";
    while (ss >> sw) {
        p += Alfa[sw];
    }
    if (p.length() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::vector<int> primes = spr();
        int num = std::stoi(p);
        auto it = std::upper_bound(primes.begin(), primes.end(), num);
        int a = it == primes.begin() ? *primes.begin() : *std::prev(it);
        it = std::lower_bound(primes.begin(), primes.end(), num);
        int b = it == primes.end() ? *std::prev(primes.end()) : *it;
        if (std::abs(num - a) > std::abs(num - b)) {
            std::cout << b << std::endl;
        } else {
            std::cout << a << std::endl;
        }
    }
    return 0;
}
